package com.itcam.phaselist.map_;

import java.util.HashMap;
import java.util.Map;

public class MapMethod {
    public static void main(String[] args) {
        Map map = new HashMap();

        map.put("李星云", new Book("", 100));
        map.put("李星云", "姬如雪"); // 替换
        map.put("张子凡", "陆林轩");
        map.put("李茂贞", "妙成天");
        map.put("女帝", "妙成天");
        map.put("本人", null);
        map.put(null, "萤勾");
        map.put("黑无常", "白无常");

        System.out.println("map = " + map);

        // remove:根据键删除映射关系
        map.remove(null);
        System.out.println("map = " + map);

        // get：根据键获取值
        Object val = map.get("李星云");
        System.out.println("val = " + val);

        // size:获取元素个数
        System.out.println("k-v = " + map.size());

        // isEmpty:判断个数是否为0 判空
        System.out.println(map.isEmpty());

        // clear:清除k-v
//        map.clear();
        System.out.println("map = " + map);

        // containsKey:查找键是否存在
        boolean key = map.containsKey("黑无常");
        System.out.println(key);

        // containsValue:查找值是否存在
        boolean value = map.containsValue("妙成天");
        System.out.println(value);
    }
}

class Book {
    private String name;
    private int num;

    public Book(String name, int num) {
        this.name = name;
        this.num = num;
    }
}